<%= javascript_tag do %>
  window.localStorage.setItem('expanded_all_results', "false");
  $(document).ready(function () {
    $("#loading").hide();
  });
$(function(){
  $('#expandall_arrow').click(function(){
        $("#loading").show();
    });

  $(document).ajaxStop(function(){
        $("#loading").hide();
    });
    });
<% end %>
<div id="loading" class="loading" style="display:nont">Loading&#8230;</div>
<div id="flash_messages">
  <%= render :partial=>"shared/notification", :locals => {:message=>@errors} if @errors.present? %>
</div>
<nav class="tab-bar">
  <section class="tab-bar-section">
    <h1>Results
      <span class="small-heading">
        <% if @results %>
          <%= page_entries_info @results  %>
          <% if @results.total_count != @total_result_count %><b>(<%= @total_result_count - @results.total_count %>
              results  filtered)</b><% end %>
        <% end %>
      </span>
    </h1>
  </section>
  <section class="buttons button-bar">
    <ul class="button-group">
      <li><a data-dropdown="table_columns_dropdown" aria-controls="table_columns_dropdown" aria-expanded="false" class="fi-widget view-button"></a>
        <div id="table_columns_dropdown" data-dropdown-content class="f-dropdown content f-dropdown-wide" aria-hidden="true" tabindex="-1">
          <%= form_tag update_table_columns_results_path do %>
            <h3>Display Fields</h3>
            <%= label_tag do %>Built-in Fields

              <%= hidden_field_tag "columns[built_in]", @index_columns.select{|c| !c.to_s.starts_with("metadata:")}.join(", "), {class: 'select2-tags', multiple:true, data:{tags: Result.valid_column_names}} %>
            <% end %>
            <%= label_tag do %>Metadata <span data-tooltip aria-haspopup="true" class="has-tip tip-left" title="Show metadata fields.<br/>Nested fields can be displayed by separating with ':'.<br/>
                 Examples: 'status_code'<br/>
                'scan:latest:timestamp'<br/>
                 Note: The same value can be used in the metadata search field to filter to only results containing a value for this field. Displaying fields containing large amounts of data could significantly impact performance."><i class="fi-info"></i></span>
              <%= hidden_field_tag "columns[metadata_fields]", @index_columns.select{|c| c.to_s.starts_with("metadata:")}.map{|c| c.gsub(/\Ametadata:/, "")}.join(", ") , {class: "select2-tags", multiple: true} %>
            <% end %>
            <%= submit_tag "Update", class: "button tiny" %> <%= submit_tag "Update and Set Default", class: "button tiny" %>
          <% end %>
        </div>
      </li>
    </ul>
  </section>
  <section class="pagination">
    <%= paginate @results, :method=>:post, :params=> nil, :outer_window => 3, :window=>1, :remote=> (defined? remote)? remote : false if @results%>
  </section>
  <section class="buttons button-bar">
    <ul class="button-group">
      <li><%= link_to "", results_path(:view=>"list"), :class=>"view-button fi-list-bullet" %></li>
      <li><%= link_to "", results_path(:view=>"tiles"), :class=>"view-button fi-thumbnails" %></li>
    </ul>
  </section>
</nav>
<div class="panel" style="display:none" id="update_all_from_page_header">
  <% if @results %>
    <p>All <%= @results.length %> results on this page selected.
    <%= link_to "Select all #{@results.total_count} results that match this filter", "#", :id=>"update_all_from_query_link" %></p>
  <% end %>
</div>
<div class="panel" style="display:none" id="update_all_from_query_header">
  <% if @results %>
    <p>All <%= @results.total_count %> results in this search selected.
      <%= link_to "Clear selection", "#", :id=>"clear_selection" %></p>
  <% end %>
</div>
<% if @view == "tiles" %>

  <%= render 'results_tiles' if @results %>
<% else %>
  <%= render 'results_table' if @results %>
<% end %>

<%= content_for :sidebar do %>
  <div class="sidebar" id="result_action_panel" style="display:none">
    <nav class="tab-bar">
      <section class="tab-bar-section">
        <h1>Actions
        </h1>
      </section>
    </nav>
    <section class="panel sidepanel">
      <%= form_tag update_multiple_results_path, method: :post, :id=>"update_multiple_form" do %>
        <%= label_tag do %>Status
          <%= select_tag :status_id, options_from_collection_for_select(Status.all, "id", "name"), {:prompt => 'Please select', class: 'select2'} %>
        <% end %>
        <%= label_tag do %>Tags
          <%= hidden_field_tag "tags", "", {class: "remote_select2", "data-multiple"=>true, "data-id-attribute"=>"name_value" , "data-parse-initial"=>"true", "data-create-new"=>"true", "data-object"=>"tags", "data-attribute"=>"name_value" , "data-path"=>tags_path} %>
        <% end %>
        <%= label_tag "Remove" do %>
          <%= check_box_tag :remove_tags, '1', false %> Remove Tag(s)
        <% end %>
        <%= label_tag do %>Assignee
          <%= select_tag :assignee_id, options_from_collection_for_select(User.all, :id, :email), {:prompt => 'Please select', class: "select2"} %>
        <% end %>
        <%= hidden_field_tag :q, params[:q].to_json %>
        <%= hidden_field_tag :update_all_from_query, false, {:id=>'update_all_from_query'} %>
        <% button_options = ["Update", "Update and Generate Screenshot", "Update and Force Generate Screenshot"] %>
        <%= split_button  button_options, :button_class=>'small', :link_class=>'update_multiple_button' %>
        <% if(can? :destroy, Result) %>
          <%= submit_tag "Delete Results", class: "button alert small update_multiple_button", data: { confirm: "Are you sure you want to delete the selected results?" } %>
        <% end %>
      <% end %>
    </section>
  </div>
<% end %>
<%= paginate @results, :method=>:post, :params=> nil, :outer_window => 3, :window=>1, :remote=> (defined? remote)? remote : false if @results %>
<br />
<%= link_to 'New Result', new_result_path, class: "button" %>
<%= link_to "Bulk Add Results", "#", :class=>"button", data:{"reveal-id"=>"bulk_add_form"} %>
<div id="bulk_add_form" class="reveal-modal custom-modal" data-reveal>
  <header class="popup-header">
    <div class="row">
      <div class="large-12 columns">
        <h4>Bulk Add Results</h4>
      </div>
    </div>
  </header>
  <div class="row">
    <div class="large-12 columns">
      <%= form_tag bulk_add_results_path do |f| %>
        <%= text_area_tag :results %>
        <%= label_tag do %>Tags
          <%= hidden_field_tag "tags", "", {class: "remote_select2", "data-multiple"=>true, "data-id-attribute"=>"name_value" , "data-parse-initial"=>"true", "data-create-new"=>"true", "data-object"=>"tags", "data-attribute"=>"name_value" , "data-path"=>tags_path} %>
        <% end %>
        <%= label_tag "tag_new_only" do %>
          <%= check_box_tag :tag_new_only, '1', false %> Only Tag New Results
        <% end %>
        <%= submit_tag "Submit", :class=>"button tiny preload" %>
        <%= button_tag "Cancel", :type=>:button, :class=>"button secondary tiny close-modal" %>
      <% end %>
    </div>
  </div>
</div>
<%= content_for :sidebar do %>
  <div class="sidebar">
    <nav class="tab-bar">
      <section class="tab-bar-section">
        <h1>Filter
        </h1>
      </section>
    </nav>
    <section class="panel sidepanel">
      <%= search_form_for @q, :url=>search_results_path, :method=>:post, :authenticity_token => false, id:"search_form"  do |f| %>
        <%= render partial: 'search_fields', locals: {f: f}%>
        <%= f.submit class: "button small" %>
        <%= f.submit "Clear Search", class: "button secondary small" %>
        <%= f.submit "Save", class: "button secondary small" %>
        <%#= f.button "Reset", type: :reset, class:"secondary" %>
      <% end %>
    </section>
  </div>
<% end %>
